
package ch.hearc.coursJava.kitBase.tab2D;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import ch.hearc.coursJava.kitBase.tools.TabTools;

public class MatrixTest
	{

	/*------------------------------------------------------------------*\
	 |*							Constructeurs							*|
	 \*------------------------------------------------------------------*/

	@Before
	public void before()
		{
		// rien
		}

	@After
	public void after()
		{
		// rien
		}

	/*------------------------------------------------------------------*\
	 |*							Methodes Public							*|
	 \*-----------------------------------------------------------------*/

	@Test
	public void testIsMultCompatible()
		{
		double[][] m1 = new double[3][2];
		double[][] m2 = new double[3][3];
		double[][] m3 = new double[2][7];

		UseTableau2D.fill(m1);
		UseTableau2D.fill(m2);
		UseTableau2D.fill(m3);

		assertTrue(Matrix.isMultCompatible(m2, m2));
		assertTrue(Matrix.isMultCompatible(m1, m3));
		assertFalse(Matrix.isMultCompatible(m3, m1));

		}

	@Test
	public void testMult()
		{
		double[][] m1 = new double[3][2];
		double[][] m2 = new double[2][4];
		double[][] resultatTheorique = new double[3][4];

		UseTableau2D.fill(m1);
		UseTableau2D.fill(m2);
		double[][] resultatObtenu = new double[3][4];
		resultatObtenu = Matrix.mult(m1, m2);
		resultatTheorique[0][0] = 373;
		resultatTheorique[0][1] = 396;
		resultatTheorique[0][2] = 419;
		resultatTheorique[0][3] = 442;
		resultatTheorique[1][0] = 693;
		resultatTheorique[1][1] = 736;
		resultatTheorique[1][2] = 779;
		resultatTheorique[1][3] = 822;
		resultatTheorique[2][0] = 1013;
		resultatTheorique[2][1] = 1076;
		resultatTheorique[2][2] = 1139;
		resultatTheorique[2][3] = 1202;

		assertTrue(resultatObtenu[0][0]==373);
		assertTrue(resultatObtenu[0][1]==396);
		assertTrue(resultatObtenu[0][2]==419);
		assertTrue(resultatObtenu[0][3]==442);
		assertTrue(resultatObtenu[1][0]==693);
		assertTrue(resultatObtenu[1][1]==736);
		assertTrue(resultatObtenu[1][2]==779);
		assertTrue(resultatObtenu[1][3]==822);
		assertTrue(resultatObtenu[2][0]==1013);
		assertTrue(resultatObtenu[2][1]==1076);
		assertTrue(resultatObtenu[2][2]==1139);
		assertTrue(resultatObtenu[2][3]==1202);

		}

	@Test
	public void testIsRectangulaire()
		{
		double[][] matriceA = new double[4][5];
		UseTableau2D.fill(matriceA);

		assertTrue(Matrix.isRectangulaire(matriceA));

		int n = 10;
		double[][] matriceB = TabTools.creer(n);
		UseTableau2D.fill(matriceB);

		assertFalse(Matrix.isRectangulaire(matriceB));
		}

	@Test
	public void testIsSquare()
		{
		double[][] matriceA = new double[5][5];
		UseTableau2D.fill(matriceA);

		assertTrue(Matrix.isSquare(matriceA));

		double[][] matriceB = new double[5][6];
		UseTableau2D.fill(matriceB);

		assertFalse(Matrix.isSquare(matriceB));
		}

	@Test
	public void testIsAddCompatible()
		{
		double[][] matriceA = new double[5][5];
		UseTableau2D.fill(matriceA);

		double[][] matriceB = new double[5][5];
		UseTableau2D.fill(matriceB);

		assertTrue(Matrix.isAddCompatible(matriceA, matriceB));

		double[][] matriceC = new double[7][2];
		UseTableau2D.fill(matriceA);

		double[][] matriceD = new double[9][77];
		UseTableau2D.fill(matriceB);

		assertFalse(Matrix.isAddCompatible(matriceC, matriceD));
		}

	@Test
	public void testAdd()
		{
		double[][] matriceA = new double[][]{{3,2,1},{4,5,6},{1,1,1}};
		double[][] matriceB = new double[][]{{6,5,4},{7,8,9},{2,0,10}};
		double[][] resultat = Matrix.add(matriceA, matriceB);
		double[][] resultatTherorique = new double[][]{{9,7,5},{11,13,15},{3,1,11}};

		assertTrue(TabTools.isEgal(resultat, resultatTherorique));

		matriceA[0][0] = 10;
		resultat = Matrix.add(matriceA, matriceB);

		assertFalse(TabTools.isEgal(resultat, resultatTherorique));
		}
	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	}
